import SmartInputServer from '../../src/index';
import { RegisteredDevice, DeviceType, DeviceCapabilities } from '../../src/types';

/**
 * 创建测试服务器实例
 */
export function createTestServer(): SmartInputServer {
  return new SmartInputServer();
}

/**
 * 生成测试设备信息
 */
export function createTestDevice(
  type: DeviceType = 'browser',
  deviceId?: string
): Omit<RegisteredDevice, 'id' | 'timestamp' | 'socketId' | 'lastSeen' | 'isOnline'> {
  return {
    type,
    name: `Test ${type} Device`,
    capabilities: {
      canSendVoice: type === 'mobile',
      canReceiveText: type === 'browser',
      canProcessAudio: type === 'mobile',
      canGenerateQR: type === 'browser'
    }
  };
}

/**
 * 生成测试设备ID
 */
export function generateTestDeviceId(type: DeviceType = 'browser'): string {
  const timestamp = Date.now();
  const random = Math.random().toString(36).substring(2, 8);
  return `${type}_test_${timestamp}_${random}`;
}

/**
 * 等待指定时间
 */
export function wait(ms: number): Promise<void> {
  return new Promise(resolve => setTimeout(resolve, ms));
}

/**
 * 验证API响应格式
 */
export function validateApiResponse(response: any): void {
  expect(response).toHaveProperty('success');
  expect(response).toHaveProperty('timestamp');
  expect(typeof response.success).toBe('boolean');
  expect(typeof response.timestamp).toBe('number');
}

/**
 * 验证错误响应格式
 */
export function validateErrorResponse(response: any, expectedStatus: number = 400): void {
  expect(response.status).toBe(expectedStatus);
  expect(response.body).toHaveProperty('success', false);
  expect(response.body).toHaveProperty('error');
  expect(response.body.error).toHaveProperty('code');
  expect(response.body.error).toHaveProperty('message');
} 